﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AssignEvent.aspx.cs" Inherits="DonationTracker.Account.Admin.AssignEvent" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:DropDownList ID="ddlCharity" runat="server" AutoPostBack="True" 
        DataSourceID="dsCharityDropDown" DataTextField="name" 
        DataValueField="charityID">
    </asp:DropDownList>
    <br />
    <br />
    <asp:SqlDataSource ID="dsAssignEventGrid" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DonationConn %>" 
        DeleteCommand="DELETE FROM [donation] WHERE [donationNumber] = @donationNumber" 
        InsertCommand="INSERT INTO [donation] ([donorID], [description], [dateEntered], [enteredBy], [eventID]) VALUES (@donorID, @description, @dateEntered, @enteredBy, @eventID)" 
        SelectCommand="SELECT DonationNumber, donor.firstName + ' ' + donor.lastName AS Donor, Donation.Description, event.name AS Event, DateEntered, aspnet_users.UserName AS EnteredBy FROM Donation 
INNER JOIN aspnet_users ON Donation.EnteredBy = aspnet_users.UserId
INNER JOIN donor ON donation.donorID = donor.donorID
INNER JOIN event ON Donation.eventID = event.eventID 
WHERE  Donation.charityID = @charityID" 
        
        
        
        UpdateCommand="UPDATE [donation] SET [eventID] = @eventID WHERE [donationNumber] = @donationNumber" >
        <DeleteParameters>
            <asp:Parameter Name="donationNumber" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="donorID" Type="Int32" />
            <asp:Parameter Name="description" Type="String" />
            <asp:Parameter DbType="Date" Name="dateEntered" />
            <asp:Parameter Name="enteredBy" Type="Object" />
            <asp:Parameter Name="eventID" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlCharity" Name="charityID" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <%--<asp:Parameter Name="enteredBy" Type="Object" />--%>
            <asp:Parameter Name="eventID" Type="Int32" />
            <asp:Parameter Name="donationNumber" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="dsCharityDropDown" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DonationConn %>" 
        SelectCommand="SELECT [name], [charityID], [order] FROM [charity] ORDER BY [order]">
    </asp:SqlDataSource>
    <br />
    <asp:GridView ID="gvAssignEvent" runat="server" 
        onrowupdating="gvAssignEvent_RowUpdating" AutoGenerateColumns="False" 
        DataKeyNames="DonationNumber" DataSourceID="dsAssignEventGrid">
        <Columns>
            <asp:CommandField ShowEditButton="True" />
            <asp:BoundField DataField="DonationNumber" HeaderText="DonationNumber" 
                InsertVisible="False" ReadOnly="True" SortExpression="DonationNumber" />
            <asp:BoundField DataField="Donor" HeaderText="Donor" 
                SortExpression="Donor" ReadOnly="True" />
            <asp:BoundField DataField="Description" HeaderText="Description" 
                SortExpression="Description" ReadOnly="True" />
            <asp:TemplateField HeaderText="Event" SortExpression="eventID">
                <EditItemTemplate>
                    <asp:DropDownList ID="ddlEvent" runat="server" DataSourceID="dsEventDropDown" 
                        DataTextField="name" DataValueField="eventID">
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Event") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="DateEntered" HeaderText="DateEntered" 
                SortExpression="DateEntered" ReadOnly="True" />
            <asp:BoundField DataField="EnteredBy" HeaderText="EnteredBy" 
                SortExpression="EnteredBy" ReadOnly="True" />
        </Columns>
    </asp:GridView>
    <br />
    <asp:SqlDataSource ID="dsEventDropDown" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DonationConn %>" 
        SelectCommand="SELECT [eventID], [name] FROM [event]"></asp:SqlDataSource>
    <br />
    <br />
</asp:Content>
